🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / ble / src / commonMain / kotlin / org / meshtastic / core / ble / KableBleScanner.kt
Displaying Raw • Download
core/ble/src/commonMain/kotlin/org/meshtastic/core/ble/KableBleScanner.kt f07624be882e679affc02931dc75e8cb1594de18 (f07624be) Text, 2.13 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.ble
Tff7b72import T7ee787com.juul.kable.Scanner
Tff7b72import T7ee787kotlinx.coroutines.flow.Flow
Tff7b72import T7ee787kotlinx.coroutines.flow.channelFlow
Tff7b72import T7ee787kotlinx.coroutines.withTimeoutOrNull
Tff7b72import T7ee787org.koin.core.annotation.Single
Tff7b72import T7ee787kotlin.time.Duration
Tff7b72import T7ee787kotlin.uuid.Uuid
Tf0883e@Single
Tff7b72class T56d364KableBleScanner Tb4b4b4: Te6edf3BleScanner Tb4b4b4{
Tff7b72override Tff7b72fun Td2a8ffscanTb4b4b4(Te6edf3timeoutTb4b4b4: Te6edf3DurationTb4b4b4, Te6edf3serviceUuidTb4b4b4: Te6edf3Uuid?Tb4b4b4, Te6edf3addressTb4b4b4: Tffa657String?Tb4b4b4)Tb4b4b4: Te6edf3FlowTff7b72<Te6edf3BleDeviceTff7b72> Tb4b4b4{
Tff7b72val Te6edf3scanner Tff7b72= Te6edf3Scanner Tb4b4b4{
T8b949e// Use separate match blocks so each filter is evaluated independently (OR semantics).
T8b949e// Combining address and service UUID in a single match{} creates an AND filter which
T8b949e// silently drops results on OEM stacks (Samsung, Xiaomi) when the device uses a
T8b949e// random resolvable private address.
Tff7b72if Tb4b4b4(Te6edf3address Tff7b72!Tff7b72= Tff7b72nullTb4b4b4) Tb4b4b4{
Te6edf3filters Tb4b4b4{ Te6edf3match Tb4b4b4{ Tff7b72thisTb4b4b4.Te6edf3address Tff7b72= Te6edf3address Tb4b4b4} Tb4b4b4}
Tb4b4b4} Tff7b72else Tff7b72if Tb4b4b4(Te6edf3serviceUuid Tff7b72!Tff7b72= Tff7b72nullTb4b4b4) Tb4b4b4{
Te6edf3filters Tb4b4b4{ Te6edf3match Tb4b4b4{ Te6edf3services Tff7b72= Te6edf3listOfTb4b4b4(Te6edf3serviceUuidTb4b4b4) Tb4b4b4} Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
T8b949e// Kable's Scanner doesn't enforce timeout internally, it runs until the Flow is cancelled.
T8b949e// By wrapping it in a channelFlow with a timeout, we enforce the BleScanner contract cleanly.
Tff7b72return Te6edf3channelFlow Tb4b4b4{
Te6edf3withTimeoutOrNullTb4b4b4(Te6edf3timeoutTb4b4b4) Tb4b4b4{
Te6edf3scannerTb4b4b4.Te6edf3advertisementsTb4b4b4.Te6edf3collect Tb4b4b4{ Te6edf3advertisement Tff7b72-Tff7b72> Te6edf3sendTb4b4b4(Te6edf3KableBleDeviceTb4b4b4(Te6edf3advertisementTb4b4b4)Tb4b4b4) Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.04s